package com.ruibo.tax.repository;

import com.ruibo.tax.model.HBJHXKZJBXX;
import com.ruibo.tax.model.log.TaxSendLog;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;

import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @description: 排污许可基本信息 UNSEND
 * @author: 孙 峰
 * @time: 2020/10/14 10:48
 */
public interface HBJHXKZJBXXRepository extends JpaRepository<HBJHXKZJBXX, Integer> {

    /**
     * 分页获取需要发送的pwxkz数据
     *
     * @param receiptStatus
     * @param status
     * @param pageable
     * @return
     */
    Page<HBJHXKZJBXX> findByStatusAndReceiptStatus(String receiptStatus, String status, Pageable pageable);

    /**
     * 根据发送状态获取需要发送的数据
     *
     * @param status
     * @param sendStatus
     * @param pageable
     * @return
     */
    Page<HBJHXKZJBXX> findByStatusAndSendStatus(String status, String sendStatus, Pageable pageable);

    /**
     * 根据税务数据接收状态查询数量
     *
     * @param status
     * @param sendStatus 发送状态
     * @return
     */
    Integer countAllByStatusAndSendStatus(String status, String sendStatus);

    /**
     * 根据回执报文跟新接受状态
     *
     * @param receiptStatus
     * @param uuid
     */
    @Modifying
    @Query(value = "update hbjh_xkz_jbxx  set receipt_status=?1 where UUID=?2 ", nativeQuery = true)
    void updateReceiptStatusByUUID(String receiptStatus, String uuid);

    /**
     * 根据接受状态  和发送次数获取  需要重新发送的数据
     *
     * @param receiptStatus
     * @param times
     * @return
     */
    Page<HBJHXKZJBXX> findAllByReceiptStatusAndSendStatusAndTimesLessThan(String receiptStatus, int times, String sendStatus, Pageable pageable);

    /**
     * 获取需要重新发送
     *
     * @param receiptStatus
     * @param times
     * @return
     */
    int countAllByReceiptStatusAndSendStatusAndTimesLessThan(String receiptStatus, String sendStatus, int times);


}
